/*
 * Copyright (c) 2010-2011 Plugger Antonio Begue Ponce. All Rights Reserved.
 *
 * This file is part of Plugger Framework.
 *
 *  Plugger Framework is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU Lesser General Public License version 3 as published by
 *  the Free Software Foundation.
 *
 *  Plugger Framework is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public License
 *  along with Plugger Framework.  If not, see <http://www.gnu.org/licenses/>.
 */

package org.plugger.infrastructure.rules;

/**
 * An implementation of CompositeRule that allow AND compositions of rules.
 * The AndRule validate concatenated rules with AND operator.
 *
 * @author Antonio Begue
 * @version $Revision: 1.0 $
 */
public class AndRule extends CompositeRule {
    private IRule _one;
    private IRule _other;

    /**
     * AndRule constructor that concatenate two rules with AND composition.
     * @param one The first rule of the composition
     * @param other The second rule of the composition
     */
    public AndRule(IRule one, IRule other) {
        _one = one;
        _other = other;
        this.addChildComponent(_one);
        this.addChildComponent(_other);
    }

    @Override
    public boolean isValid() {
        return (_one.isValid() && _other.isValid());
    }

    @Override
    public String formatMessage(String message) {
        return message;
    }
}
